<?php


@session_start();

extract($_REQUEST);

require_once "../lib/config.php";
require_once "../lib/functions.php";
require_once "../lib/pdomanager.php";
require_once "../lib/paginate_class.php";

$pdodbobj=new DB();
$pdodbobj->dbname=DBNAME;
$pdodbobj->hostname=HOST;
$pdodbobj->dbusername=USERNAME;
$pdodbobj->dbpassword=PASSWORD;
$pdodbobj->dbtype=TYPE;
$pdodbobj->portnumber=PORTNUMBER;

$starcount=1;

$connstatus=$pdodbobj->connect();

if(isset($fname) && isset($lname) && isset($vid) && isset($emailid) && $vid!='' && $emailid!='')
{
    $selecquery="select User_ID from af_users where Email_ID=:emailid";
    $usersinfo=$pdodbobj->fetch_array($pdodbobj->query($selecquery,array(":emailid"=>$emailid)));
    if(count($usersinfo)>0)
    {
        echo "000100";
    } 
    else
    {
        $insertarr=array("Full_Name"=>$fullname);
        $insertarr["Last_Name"]=$lname;
        $insertarr["Email_ID"]=$emailid;
        
        $mailidarr=explode("@",$emailid);
        $Allyfoliouserid=$mailidarr[0];
        
        $checkforid=$pdodbobj->fetch_array($pdodbobj->query("select Allyfolio_User_ID from af_users where Allyfolio_User_ID like :allyfolioid order by User_ID desc",array("allyfolioid"=>"%".$Allyfoliouserid."%")));
        
        if(count($checkforid)>0)
        {
            $allyfolioid=str_ireplace("@allyfolio.in","",$checkforid[0]['Allyfolio_User_ID']);
            $existmailidarr=explode("_",$allyfolioid);
            if(count($existmailidarr)>1)
            {
                $Allyfoliouserid=$mailidarr[0]."_".(intval($existmailidarr[1])+1)."@allyfolio.in";
            }
            else
            {
                $Allyfoliouserid=$mailidarr[0]."_1@allyfolio.in";
            }
            
        }
        else
        {
            $Allyfoliouserid.="@allyfolio.in";
        }
        
        $insertarr['Allyfolio_User_ID']=$Allyfoliouserid;
        
        $insertarr["Password"]=md5(trim("1233245321"));
        $insertarr["Gender"]=$gender;
        $insertarr["Social_Signup_Via"]=$via;
        $insertarr["Social_ID"]=$vid;
        $insertarr["Registration_Date"]=time();
        $insertarr["Activation_Status"]="Active";
        $randomstring=random_string(20);
        $insertarr["Verify_Random_String"]="";
        $insertarr=sanitize($insertarr);
        $pdodbobj->insertData("af_users",$insertarr);
        if($pdodbobj->affectedrows>0)
        {
            echo "100100";
        }
    }      
}
else
{
    echo "No Data Recieved";
}

?>